<?
        require_once('../../Inc/Global.php');
        require_once('AddressData.php');
        if(isset($_REQUEST['Submit']))
        {
                $rs = $_REQUEST;
                if(!$errors = ValidateAddress($rs))
                {
                	if(isset($_REQUEST['ID']))
                	{
                		if(!$errors = SaveAddress($rs))
                		{
                    		header("location: index.php");
                		}
                	}
                	else
                	{
                		if(!$errors = AddAddress($rs))
                  		{
                    		header("location: index.php");
                		}
                		
                	}
                }
               
        }else{
        		if(isset($_REQUEST['ID']))
        		{
                	$rs = GetAddress($_REQUEST['ID']);
        		}
        		else
        		{
        			$rs = NewAddress();
        			# Create a blank associative array -> set it up this way for error handling
        		}
        }
?>
<!DOCTYPE html>
<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Edit Address: <?=$rs['Address_Line1']?> <?=$rs['Address_Line2']?></title>
        <link rel="stylesheet" type="text/css" href="../Main.css" />
</head>
<body>
	<p>This is the create/add Address screen.</p>
        
        <form method="post">
                        <div>
                                <label>ID:</label>
                                <?=$rs['ID']?>
                        </div>
                        <br />
                        <div>
                                <label>Category ID:</label>
                                <?=$rs['Category_ID']?>
                        </div>
                        <br />
                        <div>
                                <label>Person ID:</label>
                                <?=$rs['Person_ID']?>
                        </div>
                        <br />
                        <div>
                                <label for="Address_Line1">Address Line 1:</label>
                                <input  type="text" name="Address_Line1" id="Address_Line1"
                                                class="<? if(isset($errors['Address_Line1'])){ ?>error<? } ?>"
                                                value="<?=$rs['Address_Line1']?>" />
                                                <? if(isset($errors['Address_Line1'])){ ?>
                                                        <span class="error"><?=$errors['Address_Line1']?></span>
                                                <? } ?>
                        </div>
                        <div>
                                <label for="Adress_Line2">Address Line 2:</label>
                                <input  type="text" name="Address_Line2" id="Address_Line2"
                                <?=$rs['Address_Line2']?>" />                   
                        </div>
                        <div>
                                <label for="City">City:</label>
                                <input  type="text" name="City" id="City"
                                                class="<? if(isset($errors['City'])){ ?>error<? } ?>"
                                                value="<?=$rs['City']?>" />
                                                <? if(isset($errors['City'])){ ?>
                                                        <span class="error"><?=$errors['City']?></span>
                                                <? } ?>
                        </div>
                        <div>
                                <label for="State">State:</label>
                                <select name="State">
									<option value="AL">Alabama</option>
									<option value="AK">Alaska</option>
									<option value="AZ">Arizona</option>
									<option value="AR">Arkansas</option>
									<option value="CA">California</option>
									<option value="CO">Colorado</option>
									<option value="CT">Connecticut</option>
									<option value="DE">Delaware</option>
									<option value="DC">District of Columbia</option>
									<option value="FL">Florida</option>
									<option value="GA">Georgia</option>
									<option value="HI">Hawaii</option>
									<option value="ID">Idaho</option>
									<option value="IL">Illinois</option>
									<option value="IN">Indiana</option>
									<option value="IA">Iowa</option>
									<option value="KS">Kansas</option>
									<option value="KY">Kentucky</option>
									<option value="LA">Louisiana</option>
									<option value="ME">Maine</option>
									<option value="MD">Maryland</option>
									<option value="MA">Massachusetts</option>
									<option value="MI">Michigan</option>
									<option value="MN">Minnesota</option>
									<option value="MS">Mississippi</option>
									<option value="MO">Missouri</option>
									<option value="MT">Montana</option>
									<option value="NE">Nebraska</option>
									<option value="NV">Nevada</option>
									<option value="NH">New Hampshire</option>
									<option value="NJ">New Jersey</option>
									<option value="NM">New Mexico</option>
									<option value="NY">New York</option>
									<option value="NC">North Carolina</option>
									<option value="ND">North Dakota</option>
									<option value="OH">Ohio</option>
									<option value="OK">Oklahoma</option>
									<option value="OR">Oregon</option>
									<option value="PA">Pennsylvania</option>
									<option value="RI">Rhode Island</option>
									<option value="SC">South Carolina</option>
									<option value="SD">South Dakota</option>
									<option value="TN">Tennessee</option>
									<option value="TX">Texas</option>
									<option value="UT">Utah</option>
									<option value="VT">Vermont</option>
									<option value="VA">Virginia</option>
									<option value="WA">Washington</option>
									<option value="WV">West Virginia</option>
									<option value="WI">Wisconsin</option>
									<option value="WY">Wyoming</option>
						</select>
                                                                                             
                        </div>
                        <div>
                                <label for="Zipcode">Zipcode:</label>
                                <input  type="text" name="Zipcode" id="Zipcode"
                                                class="<? if(isset($errors['Zipcode'])){ ?>error<? } ?>"
                                                value="<?=$rs['Zipcode']?>" />
                                                <? if(isset($errors['Zipcode'])){ ?>
                                                        <span class="error"><?=$errors['Zipcode']?></span>
                                                <? } ?>
                        </div>	
						<div>
                                <label for="Country">Country:</label>
                                <input  type="text" name="Country" id="Country"
                                <?=$rs['Address_Line2']?>" />                   
                        </div>
                        <div>
                                <label>Creation Date:</label>
                                <?=$rs['Created_at']?>
                        </div>
                        <br />
                        <div>
                                <label>Last Updated At:</label>
                                <?=$rs['Updated_at']?>
                        </div>
                        <br />
                        <input type="submit" name="Submit" value="Submit" />
                        <input type="button" value="Cancel" onclick="window.location.href='http://cs.newpaltz.edu/~N00001387/WebClass/DatabaseProject/AddressMgmt/'" />
        </form>
        
     <br />
     <input type="button" value="Go To Home Screen" onclick="window.location.href='http://cs.newpaltz.edu/~N00001387/WebClass/DatabaseProject/'" />
</body>
</html>

